with System;
with Interfaces.C;
with Ada.Exceptions;

package FT2.Types is

   pragma Preelaborate;

   subtype C is Character;
   --  Renaming of Character to shorten enum representations

   type Void is null record;
   pragma Convention (C, Void);
   type Void_Ptr is access all Void;
   pragma Convention (C, Void_Ptr);

   subtype FT_Bool is Interfaces.C.unsigned_char;
   -- FT_FWord
   -- FT_UWord
   -- FT_Tag
   -- FT_String
   -- FT_F2Dot14
   -- FT_Pointer
   -- FT_Offset
   -- FT_PtrDist
   -- FT_UnitVector
   -- FT_Data
   subtype FT_Byte is Interfaces.C.unsigned_char;
   subtype FT_Char is Interfaces.C.char;
   subtype FT_UChar is Interfaces.C.unsigned_char;
   subtype FT_Short is Interfaces.C.short;
   subtype FT_UShort is Interfaces.C.unsigned_short;
   subtype FT_Int is Interfaces.C.int;
   subtype FT_UInt is Interfaces.C.unsigned;
   subtype FT_Long is Interfaces.C.long;
   subtype FT_ULong is Interfaces.C.unsigned_long;
   subtype FT_UInt32 is Interfaces.Unsigned_32;

   type FT_F26Dot6 is delta 1.0 / 2**6 range -2.0**25 .. 2.0**25;
   for FT_F26Dot6'Small use 1.0 / 2**6;
   for FT_F26Dot6'Size use Interfaces.C.long'Size; -- 32;
   --  26.6 float type

   type FT_Fixed is delta 1.0 / 2**16 range -2.0**15 .. 2.0**15;
   for FT_Fixed'Small use 1.0 / 2**16;
   for FT_Fixed'Size use Interfaces.C.long'Size; -- 32;
   --  16.16 float type

   type FT_Error is new Interfaces.C.int;
   FT_Exception : exception;
   procedure Check_And_Raise (Error : FT_Error);
   -- If Error is a real error, then raise FT_Exception attaching Error to it.
   function Get_Error (X : Ada.Exceptions.Exception_Occurrence) return FT_Error;
   -- Returns the Error attached to an exception occurrence, if possible.
   -- Otherwise, return 0.

   type FT_Bytes_Ptr is access all FT_Byte;
   pragma Convention (C, FT_Bytes_Ptr);
   type FT_Byte_Array is array (Natural range <>) of aliased FT_Byte;
   function To_Array
     (Ptr : FT_Bytes_Ptr;
      Length : FT_Int)
      return FT_Byte_Array;

   type FT_Shorts_Ptr is access all FT_Short;
   pragma Convention (C, FT_Shorts_Ptr);
   type FT_Short_Array is array (Natural range <>) of aliased FT_Short;
   function To_Array
     (Ptr : FT_Shorts_Ptr;
      Length : FT_Int)
      return FT_Short_Array;

   type FT_String_Ptr is access all FT_Char;
   pragma Convention (C, FT_String_Ptr);
   function To_String (Ptr : FT_String_Ptr) return String;

   type FT_UInt32_Array is array (Natural range <>) of aliased FT_UInt32;

   ------------
   -- Matrix --
   ------------

   type FT_Matrix is record
      XX : FT_Fixed;
      XY : FT_Fixed;
      YX : FT_Fixed;
      YY : FT_Fixed;
   end record;
   pragma Convention (C, FT_Matrix);

   -------------
   -- Generic --
   -------------

   type FT_Generic_Finalizer is access procedure (Object : System.Address);
   pragma Convention (C, FT_Generic_Finalizer);

   type FT_Generic is record
      Data      : System.Address := System.Null_Address;
      Finalizer : FT_Generic_Finalizer;
   end record;
   pragma Convention (C, FT_Generic);

   -- FT_ListNode
   -- FT_ListNodeRec
   -- FT_List
   -- FT_ListRec

end FT2.Types;
